package com.xp.tinyurl.common.base;

import lombok.extern.slf4j.Slf4j;


/**
 * Created by litao-ds1 on 2016/8/22.
 */
@Slf4j
public class ResultVOBuilder {

    public static final int SUCCESS_CODE = 200;

    /**
     * 未授权
     */
    public static final int FORBID_CODE = 401;

    public static final int FAIL_CODE = 500;

    public ResultVOBuilder() {
    }

    public static <T> ResultVO<T> success() {
        return success(null);
    }

    public static <T> ResultVO<T> success(T data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(data);
        resultVO.setSuccess(true);
        resultVO.setCode(SUCCESS_CODE);
        return resultVO;
    }

    public static <T> ResultVO<T> failure(String errMsg) {
        return failure(errMsg, null);
    }
    
    public static <T> ResultVO<T> failure(String errMsg,T data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(data);
        resultVO.setSuccess(false);
        resultVO.setCode(FAIL_CODE);
        resultVO.setMsg(errMsg);
        return resultVO;
    }

    public static <T> ResultVO<T> unAuthErr(String errMsg,T data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(data);
        resultVO.setSuccess(false);
        resultVO.setCode(FORBID_CODE);
        resultVO.setMsg(errMsg);
        return resultVO;
    }

}
